﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
    <style type="text/css">
        div
        {
            border-style: solid;
            border-color: red;
            border-width: thin;
        }
        
        #result {
            width: 500px;
            height:300px;
        }
        
        #dragDiv {

            width: 100px;
            height: 50px;
        }
    </style>
    <script type="text/javascript">
        function init() {
            document.ondragover = function(e) {
                e.preventDefault();
            };
            document.ondrop = function (e) {
                e.preventDefault();
            };

            var dragDiv = document.getElementById("dragDiv");
            var resultDiv = document.getElementById("result");

            dragDiv.addEventListener("dragstart", function (ev) {
                var dt = ev.dataTransfer;
                dt.setData("text/plain",this.id);

            });

            resultDiv.addEventListener("dragend", function (e) {
                e.preventDefault();
            });

            resultDiv.addEventListener("drop", function (ev) {
                var dt = ev.dataTransfer;
                var dataId = dt.getData("text/plain");

                $("#result").append($("#" + dataId));
            });

        }
        
        

    </script>
</head>
<body onload="init();">
    <div id="dragDiv" draggable="true">
        

        被拖的元素
    </div>
    
    
    <hr/>
    <div id="result">
        目标元素
    </div>
</body>
</html>
